require 'gem_config'

module RedisHashStore
  include GemConfig::Base

  Error         = Class.new(StandardError)
  RedisNotFound = Class.new(Error)

  with_configuration do
    has :fields_per_hash, classes: Fixnum, default: 100
    has :key_prefix, classes: String, default: 'hash_store'
    has :redis
  end

  def self.redis
    @redis ||= configuration.redis || (defined?(Redis.current) && Redis.current) or fail RedisNotFound, 'Redis not configured.'
  end
end

require_relative 'redis_hash_store/version'
require_relative 'redis_hash_store/actions'
require_relative 'redis_hash_store/rails_cache' if defined?(Rails)
